package com.zhiyou.controller;

import com.github.pagehelper.PageInfo;
import com.zhiyou.entity.Role;
import com.zhiyou.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;
    @RequestMapping("/getAll")
    public PageInfo<Role> getAll(String like,Integer pageNo,Integer pageSize){
        PageInfo<Role> pageInfo =roleService.getAll(like,pageNo,pageSize);
        return pageInfo;
    }

//    添加角色
    @RequestMapping("/insert")
    public int insert(String rName,String rDesc){
      int i = roleService.insert(rName,rDesc);
      return i;

    }
//    删除角色
    @RequestMapping("/delete")
    public int delete(Integer rId){
        int i=roleService.delete(rId);
        return i;
    }
//    检查是否有这角色
    @RequestMapping("/checkRName")
    public Map<String,Object> checkRName(String rName){
        Map<String, Object> map = new HashMap<>();
        boolean flag = roleService.checkRName(rName);
       map.put("success",flag);
        return  map;
    }

//    修改角色之前   根据Rid查询用户显示到模态窗口
    @RequestMapping("/selectOneByRId")
    public Role selectOneByRId(Integer rId){
   Role  role= roleService.selectOneByRId(rId);
        return role;
    }
//    执行更新操作
    @RequestMapping("/update")
    public int update(Role role){
        int i=roleService.update(role);
        return i;
    }

}
